(function ($) {
	$.init();
	$.plusReady(function () {
	    baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		
		requestExamine()
		// var slider = document.getElementById('slider');
		// slider.addEventListener('slide', function(event) {
		// 	var index = event.detail.slideNumber;
		// 	refreshMainPage(index)
		// 	$('#sliderIndicator .mui-indicator[data-index="'+index+'"]')[0].classList.add('mui-active');
		// });
		var indicators = document.querySelectorAll('#sliderIndicator .mui-indicator');
		for (var i = 0; i < indicators.length;i++) {
			indicators[i].addEventListener('tap',function(){
				var oldActive = $('#sliderIndicator .mui-indicator.mui-active')[0];
				if (oldActive) {
					if (oldActive == this) {
						return
					}
					oldActive.classList.remove('mui-active')
				}
				var newIndex = parseInt(this.getAttribute('data-index'))
				refreshMainPage(newIndex);
				this.classList.add('mui-active')
				mui('#slider').slider().gotoItem(newIndex,100)
			});
		}
	}
	
	// 获取表头
	function requestExamine() {
		const user = app.getState();
		var arg = {
			loginID: user.loginID,
			APPLoginID: user.loginID,
			APPPerID: user.loginPerID,
			parr: ''
		}
		// 获取详情
		var method = 'web.INMPlatform:FindApprovalByUser'
		paramDict = {
			'method': method,
			'params': JSON.stringify(arg),
			'type': 'RecQuery'
		}
		// console.log(JSON.stringify(arg));
		$.DHCWebService(paramDict, function(result) {
			var dataArr = result['data'];
			// console.log(JSON.stringify(dataArr));
			var examHtml = ''
			for (let i = 0; i < dataArr.length; i++) {
				// {"desc":"护士离职","keyID":"23||1","num":"2","Color":"#20A0FF","Type":"C","rw":"23","MenuID":"7-95","Router":"NurseResign","params":"","MenuName":"护士离职"}
				var desc = dataArr[i].desc
				var num = dataArr[i].num;
				var keyID = dataArr[i].keyID;
				var rw = dataArr[i].rw;
				var Type = dataArr[i].Type;
				var color = dataArr[i].Color;
				// console.log(rw)
				// B：待办 AC：审批
				if (Type != 'A') {
					var li = '<li class="mui-table-view-cell" data-rw="' + rw + '" keyID="' + keyID +
						'"><div class="cell"><div class="extitle" style="color:' + color + '">' + desc +
						'</div>' +
						'</div><span class="mui-badge exaNum" style="background:' + color + '">' + num +
						'</span><span class="exaDate">' + '' + '</span></li>'
					examHtml += li;
				}
			}
			var tableView = document.querySelector('#unexamWrapper .mui-table-view');
			if(examHtml != ''){
				hideNullTip(0)
				tableView.innerHTML = examHtml;
			}else{
				showNullTip(0,'暂时没有待办，去其他地方看看吧！')
			}
			//	待办事项 点击事件
			$('#unexamWrapper .mui-table-view-cell').each(function() {
				this.addEventListener('tap',function(){
					mui.toast('努力开发中')
					return
					var list = '../HomePages/examCardList.html'
					var title = this.querySelector('.extitle').innerText;
					var rw = this.getAttribute('data-rw');
					var keyID = this.getAttribute('keyID');
					console.log(rw)
					console.log(keyID)
					if (keyID) {
						webview = plus.webview.create(list, 'todoCardList.html', {
							titleNView: {
								backgroundColor: '#fff',
								titleText: title,
								titleSize: '18px',
								titleColor: '#1D2334',
								autoBackButton: true,
							}
						}, {
							keyID: keyID,
							rw: rw
						});
						webview.show('pop-in');
					}
				})
			})
	
		}, function(errorStr) {
			console.log(errorStr)
		});
	}
	function showNullTip(index,msg){
		mui('.nullData')[index].style.display = 'block';
		mui('.nullTip')[index].innerHTML = msg
	}
	
	function hideNullTip(index){
		// console.log(index)
		mui('.nullData')[index].style.display = 'none';
	}
	///刷新
	function refreshMainPage(index){
		
	}
})(mui);